<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Cookie;
class Login extends Common
{
	
    public function login()
    {
		$request = Request::instance();
		if(!empty($request->route()['jump']))
		{
		  $jump = $request->route()['jump'];
		}else{
		  $jump = 'index';
		}
		return view('login/login',['jump'=>$jump]);		
	}
	public function logins(){
		$username=input('post.username');
		$password=md5(input('post.password'));
		$jump=input('post.jump');
		$url=config('tdwApi')."/login/login.jhtml?username=$username&password=$password";
		$res=$this->http($url);
		$res=json_decode($res[0],true);
		if($res['code']==1){
			Cookie::set('userInfo',$res['data'],7200);
			$res['jump']=$jump;			
		}
		echo json_encode($res);
	}
	public function loginCode(){
		$mobile=input('post.mobile');
		$code=input('post.code');
		$jump=input('post.jump');
		$url=config('tdwApi')."/login/loginByCode.jhtml?mobile=$mobile&validatecode=$code";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			Cookie::set('userInfo',$res['data'],7200);
			$res['jump']=$jump;
		}
		echo json_encode($res);		
	}
	public function sendSMS(){
		$mobile=input('get.mobile');
		$url=config('tdwApi')."/login/sendSMSForLogin.jhtml?mobile=$mobile";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		echo json_encode($res);		
	}
	public function logout(){
		Cookie::delete('userInfo');
        if(Cookie::has('userInfo')==true) {
			$this->error('退出失败！');            
        }else{
			$this->success('退出成功！',url('index/Index/login'),'',3);
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
